home *** CD-ROM | disk | FTP | other *** search
- Path: soap.news.pipex.net!pipex!usenet
- From: Barry Warburton <ge68@dial.pipex.com>
- Newsgroups: comp.lang.c++
- Subject: Re: C++ Gurus! Is it correct?
- Date: 2 Feb 1996 11:12:48 GMT
- Organization: UnipalmPIPEX server (post doesn't reflect views of UnipalmPIPEX)
- Message-ID: <4esrjg$g6l@soap.news.pipex.net>
- References: <4eqvtg$cg5@israel-info.datasrv.co.il>
- NNTP-Posting-Host: aj105.du.pipex.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.1 (Windows; I; 16bit)
-
- dmitry@enigma.co.il (Dmitry A. Davidovich) wrote:
- >Is next code is correct from point of view of pure C++ ?
- >
- >class A
- >{
- >};
- >
- >class B
- >{
- >};
- >
- >class C : public A, public B
- >{
- >};
- >
-
- int main(){
- >A* pA = new C;
- // pA= (A*) new C;
- >B* pB = new C;
- // pB= (B*) new C;
- >
- >delete pA;
- >delete pB;
- >
- return 0;
- }
-
- >Please, mail me copy of response.
- >
- >+++++++++++++++++++++++++++++++++++++++++
- >Dmitry Davidovich
- >CS Tel Aviv University
- >dmitry@enigma.co.il
- >ddmitry@libra.math.tau.ac.il
- >+++++++++++++++++++++++++++++++++++++++++
- >
- The thing that you wanted to ask is whether we can delete
- the references to the multiple inherited class without
- corrupting memory.
-
- ANSWER
- This depends on the compiler,
- But as usual with C++ newer compiler versions give a better chance of
- success.
-
- The multiple inheritance problem is usually solved by making a pointer
- conversion which changes the address of the pointer.
-
- A pA= new C; // pA points to the A part of C
- B pB= new C; // pB points to the B part of C
-
- delete pA; // delete A address
- delete pB; // delete B address
-
- In some C++ compilers you are prohibited to do these conversions,
- unless you specify one of the base-classes as virtual, which will
- allow you to do only one conversion.
-
- A compiler that would compile it correctly would keep a seperate
- delete offset in the virtual-function table of the class.
-
- delete pA becomes:
- free( pA+ pA->class->deleteOffset);
- free( pB+ pB->class->deleteOffset);
-
- The implementation will differ accross compilers,
- if the compiler DID implement it.
-
- I hope this answers your questions.
-
-
- Dirk Wessels
- Deleloper C++/Delphi/Smalltalk
-
-
-